home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / General / Controls GH / Slider Control GH / Slider.c < prev    next >
C/C++ Source or Header  |  1993-10-22  |  18KB  |  659 lines

  1. /************** Slider.c v1.0 *********
  2. ******* code for a slider type control CDEF
  3. *******©1993 Glenn R. Howes
  4. ******* all rights reserved *****/
  5. // #include "Slider.h" included in the prefix option
  6.  
  7. #include "utilities.h"
  8. pascal long main(short variation, ControlHandle me,
  9.                 short msg, long param)
  10. {
  11.     long result = 0L;
  12.  
  13.  
  14.     switch (msg)
  15.     {
  16.         case testCntl: // determine if mouse down is in control
  17.             result = TestMe(me, HiWord(param), LoWord(param));
  18.         break;
  19.         case calcCRgns: // 24-bit means of requesting shape of control or part
  20.             result = CalcStripRegion(me, (RgnHandle)param);
  21.         break;
  22.         case initCntl: // 1st message, allocate private data
  23.             InitMe(me);
  24.         break;
  25.         case dispCntl: // last message, dispose private data
  26.             if ((*me)->contrlData)
  27.                 DisposeHandle((*me)->contrlData);
  28.         break;
  29.         case posCntl: // given new point (and old point from the thumbCntl msg)
  30.                     // set the controls new value
  31.             PositionMe(me, HiWord(param), LoWord(param));
  32.         break;
  33.         case thumbCntl: // request for info for use in dragging thumb outline
  34.                         // also gives point at which drag starts
  35.             ProvideDragInfo(me, (ThumbInfo*)param);
  36.         break;
  37.         case dragCntl: // we aren't doing any custom tracking ignore
  38.         break;
  39.         case autoTrack: // we aren't doing any custom tracking ignore
  40.             // result = TrackMe(me, LoWord(param));
  41.         break;
  42.         case calcCntlRgn: // 32-bit clean message asking for whole cntl region
  43.             CalcRegion( me, (RgnHandle)param, FALSE);
  44.             result = 1L;
  45.         break;
  46.         case calcThumbRgn: // 32-bit clean message asking for shape of thumb
  47.             result =  CalcRegion( me, (RgnHandle)param, TRUE);
  48.             result =  1L;
  49.         break;
  50.         case drawCntl: // draw control or part of control
  51.             DrawMe(me, LoWord(param));
  52.         break;
  53.     }
  54.     
  55.     
  56.     return (result);
  57. }
  58. /******************* ProvideDragInfo ***********
  59. **** a mouse down has occurred in the thumb and we are
  60. **** asked to proide information used by the toolbox routine
  61. **** DragGrayRgn to confine the drag to a given rectangle 
  62. ****  the limit rect is the rect in which the region will move
  63. ****  the slop rect is the rect in which the mouse can be and the
  64. ****  gray outline will still be visible.
  65. ****  Notice that I'm taking into account the position within the
  66. ****  thumb so that the region doesn't go beyond the control****/
  67. void ProvideDragInfo(ControlHandle me, ThumbInfo *param)
  68.     Rect            ctlRect, thumbRect;
  69.     PrivateHandle    privData;
  70.     Point            entry;
  71.     privData = (PrivateHandle)(*me)->contrlData;
  72.     
  73.     // the original mousedown point is stored in the top,left corner of
  74.     // the thumbinfo's limitRect field
  75.     
  76.     entry.h = param->limitRect.left;
  77.     entry.v = param->limitRect.top;
  78.     if (privData)
  79.     {
  80.         (*privData)->entryPoint.h = entry.h;
  81.         (*privData)->entryPoint.v = entry.v;
  82.     }
  83.     CopyRect(&(*me)->contrlRect, &ctlRect);
  84.     CalcThumbRects(me, (*me)->contrlValue, &thumbRect);
  85.     
  86.     if ((ctlRect.bottom - ctlRect.top) // if we are a vertical control
  87.         >= (ctlRect.right - ctlRect.left))
  88.     {
  89.         ctlRect.bottom -= (thumbRect.bottom - entry.v);
  90.         ctlRect.top += (entry.v - thumbRect.top);
  91.         
  92.         CopyRect(&ctlRect, ¶m->limitRect);
  93.     
  94.         param->axis = 2; // confine to vertical
  95.     }
  96.     else // if we are a horizontal control
  97.     {
  98.         ctlRect.right -= (thumbRect.right - entry.h) -1;
  99.         ctlRect.left += (entry.h - thumbRect.left);
  100.         
  101.         CopyRect(&ctlRect, ¶m->limitRect);
  102.     
  103.         param->axis = 1; // confine to horizontal
  104.  
  105.     }
  106.     InsetRect(&ctlRect, -5, -5); // make slop bigger than ctl rect
  107.     CopyRect(&ctlRect, ¶m->slopRect);
  108. }
  109. /************ PositionMe *************
  110. ******** I've been dragged, with the sequence 
  111. ****** TestMe, ProvideDragInfo, and now PositionMe
  112. ****** so the delta values are changes from the original mousedown *****/
  113. void PositionMe(ControlHandle me, short deltaV, short deltaH)
  114. {
  115.     Point    newPoint;
  116.     
  117.     MapValue2Point(me, (*me)->contrlValue, &newPoint);
  118.     newPoint.v += deltaV;
  119.     newPoint.h += deltaH;
  120.     
  121.     MapPt2Value(me, &newPoint, &(*me)->contrlValue);
  122.     DrawMe(me, 0);
  123. }
  124. /************ MapPt2Value *****************
  125. ***** given a point within the control, map it to a control value
  126. ******/
  127. void MapPt2Value(ControlHandle me, Point *aPoint, short *value)
  128. {
  129.     Rect    ctlRect;
  130.     short    width, height, thumbLen, halfThumb;
  131.     long    min, max, locValue;
  132.     
  133.     CopyRect(&(*me)->contrlRect, &ctlRect);
  134.     min = (*me)->contrlMin;
  135.     max = (*me)->contrlMax;
  136.     
  137.     width = ctlRect.right - ctlRect.left;
  138.     height = ctlRect.bottom - ctlRect.top;
  139.     
  140.     thumbLen = CalcThumbLen(&ctlRect);
  141.     halfThumb = thumbLen /2;
  142.     
  143.     if (width > height)
  144.     {
  145.         ctlRect.right -= halfThumb;
  146.         ctlRect.left += halfThumb;
  147.         width -= thumbLen;
  148.         if (ctlRect.right < aPoint->h) aPoint->h = ctlRect.right;
  149.         else if (ctlRect.left > aPoint->h) aPoint->h = ctlRect.left;
  150.     
  151.         locValue = min + ((max-min)*(aPoint->h-ctlRect.left))/width;
  152.     }
  153.     else
  154.     {
  155.         ctlRect.bottom -= halfThumb;
  156.         ctlRect.top += halfThumb;
  157.         height -= thumbLen;
  158.         if (ctlRect.bottom < aPoint->v) aPoint->v = ctlRect.bottom;
  159.         else if (ctlRect.top > aPoint->v) aPoint->v = ctlRect.top;
  160.         
  161.         locValue = min + ((max-min)*(ctlRect.bottom-aPoint->v))/height;
  162.     }
  163.     *value = locValue;
  164. }
  165. /*********** MapValue2Point *********
  166. ******* given a control value, convert it to a point within
  167. ******* the control corresponding to where the center of the thumb
  168. ******* must be **********/
  169. void MapValue2Point(ControlHandle me, short value, Point *aPoint)
  170. {
  171.     Rect    ctlRect;
  172.     long    width, height;
  173.     long    min, max;
  174.     short    thumbLen, halfThumb;
  175.     CopyRect(&(*me)->contrlRect, &ctlRect);
  176.     min = (*me)->contrlMin;
  177.     max = (*me)->contrlMax;
  178.     
  179.     thumbLen = CalcThumbLen(&ctlRect);
  180.     halfThumb = thumbLen /2;
  181.     
  182.     width = ctlRect.right - ctlRect.left;
  183.     height = ctlRect.bottom - ctlRect.top;
  184.     
  185.     if (value > max)
  186.         value = max;
  187.     else if (value < min) 
  188.         value = min;
  189.  
  190.     if (width > height) // horizontal control
  191.     {
  192.         width -= thumbLen;
  193.         aPoint->h = ctlRect.left + halfThumb + (width*value)/(max-min);
  194.         aPoint->v = ctlRect.top + height/2;
  195.     }
  196.     else
  197.     {
  198.         height -= thumbLen;
  199.         aPoint->v = ctlRect.bottom - halfThumb -(height * value)/(max-min);
  200.         aPoint->h = ctlRect.left + width/2;
  201.     }
  202. }
  203.  
  204. /************* CalcStripRegion *******
  205. ******* when in 24-bit mode, we will get a region handle whose
  206. ******* 31st bit is used to indicate if the app wants the region
  207. ******* of the thumb (on) or the whole control (off).
  208. ******* We are supposed to strip off the bit and return the 
  209. ******* calculated region ******/
  210. long CalcStripRegion(ControlHandle me, RgnHandle theRegion)
  211. {
  212.     char    calcThumb;
  213.     if (Using32Bit()) // WHY IS THIS GETTING CALLED¿
  214.     {
  215.         return (CalcRegion(me, theRegion, FALSE));
  216.     }
  217.     else
  218.     {
  219.         calcThumb = (long)theRegion >> 31L; // getting high bit, on = calc thumb
  220.         theRegion = (RgnHandle)(0x7FFFFFFFL & (long)theRegion); 
  221.         // stripping out high bit only see tech note “joy of 32 bit clean”
  222.         return (CalcRegion(me, theRegion, calcThumb)); // calc the region
  223.     }
  224. }
  225. /*************** CalcRegion ******
  226. ******* figure the region of the control, or the thumb if the 
  227. ******* calcThumb parameter is non-zero **********/
  228. long CalcRegion(ControlHandle me, RgnHandle theRegion, char calcThumb)
  229. {
  230.     RgnHandle    myRegion;
  231.     Rect        ctlRect, thumbRect;
  232.     short        diameter;
  233.     myRegion = NewRgn();
  234.     if (myRegion)
  235.     {
  236.         OpenRgn();
  237.         CopyRect(&(*me)->contrlRect, &ctlRect);
  238.         diameter = CalcRounding(&ctlRect);
  239.         if (calcThumb)
  240.         {
  241.             CalcThumbRects(me, (*me)->contrlValue, &thumbRect);
  242.             FrameRoundRect(&thumbRect, diameter,diameter);
  243.         }
  244.         else
  245.         {
  246.             FrameRoundRect(&ctlRect, diameter, diameter);
  247.         }
  248.  
  249.         CloseRgn(myRegion);
  250.         InsetRgn(myRegion, -1, -1); // make it a little bigger to take into account
  251.                                     // width of lines
  252.         UnionRgn(theRegion, myRegion, theRegion);
  253.         DisposeRgn(myRegion);
  254.     }
  255.     
  256.     return ((long)theRegion);
  257. }
  258. /************ TestMe ****************
  259. ******* is the point within the control, and if so,
  260. ******* what part, there are 3 parts: thumb, pageup, 
  261. pagedown **********/
  262. long TestMe(ControlHandle me, short v, short h)
  263. {
  264.     Point            testPoint;
  265.     long            result = 0L;
  266.     Rect            ctlRect, whiteRect, grayRect, roundThumb;
  267.     
  268.     testPoint.h = h; testPoint.v = v;
  269.     
  270.     if(PtInRect(testPoint, &(*me)->contrlRect) && (*me)->contrlHilite < 255) 
  271.     // quick determination of (mouse in rect and control undimmed)
  272.     {
  273.         CopyRect(&(*me)->contrlRect, &ctlRect);
  274.         CalcGrayRect(me, &grayRect, &whiteRect);
  275.         CalcThumbRects(me,(*me)->contrlValue, &roundThumb);
  276.         if (PtInRect(testPoint, &roundThumb))
  277.         {
  278.             result = inThumb;
  279.         }
  280.         else if (PtInRect(testPoint, &grayRect))
  281.         {
  282.             result = inPageUp;
  283.         }
  284.         else
  285.         {
  286.             result = inPageDown;
  287.         }
  288.     }
  289.     return (result);
  290. }
  291. /*************** DrawMe **********
  292. ******* Draw the control or the control's thumb *****/
  293. void DrawMe(ControlHandle me, short part)
  294. {
  295.     Rect            grayRect, whiteRect, thumbRect, tempRect;
  296.     PenState        oldState;
  297.     PrivateHandle    privData;
  298.     RgnHandle        oldRegion = 0L, thumbRegion = 0L, ctlRegion =0L;
  299.     short            diameter;
  300.     
  301.     GetPenState(&oldState);
  302.     PenNormal();
  303.     privData = (PrivateHandle)(*me)->contrlData;
  304.     CalcGrayRect(me, &grayRect, &whiteRect);
  305.     CalcThumbRects(me, (*me)->contrlValue, &thumbRect);
  306.  
  307.     switch (part)
  308.     {
  309.         case 255: // change in dimming
  310.             EraseRect(&grayRect);
  311.         case 0: // draw whole thing
  312.             EraseRect(&whiteRect);
  313.             DrawMyFrame(me,&grayRect);
  314.             DrawMyIndicator(me, &thumbRect);
  315.         break;
  316.         case 129: // redraw generic indicator
  317.                 // I'm using the regions to stop the flashing of drawing 
  318.                 // the gray rect and then drawing the white thumb over it
  319.             oldRegion = NewRgn();
  320.             thumbRegion = NewRgn();
  321.             ctlRegion = NewRgn();
  322.             if (ctlRegion && thumbRegion && oldRegion && privData)
  323.             {
  324.                 diameter = CalcRounding(&(*me)->contrlRect);
  325.                 GetClip(oldRegion);
  326.                 CopyRect(&thumbRect, &tempRect);
  327.                 // InsetRect(&tempRect, -2,-2);
  328.                 OpenRgn();
  329.                     FrameRoundRect(&(*me)->contrlRect, diameter, diameter);
  330.                 CloseRgn(ctlRegion);
  331.                 OpenRgn();
  332.                     FrameRoundRect(&thumbRect, diameter, diameter);
  333.                 CloseRgn(thumbRegion);
  334.                 XorRgn(ctlRegion, thumbRegion, thumbRegion);
  335.                 SetClip(thumbRegion);
  336.                 CleanOldThumb(me, &thumbRect);
  337.                 SetClip(ctlRegion);
  338.                 DrawMyIndicator(me, &thumbRect);
  339.                 SetClip(oldRegion);
  340.             }
  341.             else // we had a memory allocation problem, draw whole thing
  342.             {
  343.                 EraseRect(&whiteRect);
  344.                 DrawMyFrame(me,&grayRect);
  345.                 DrawMyIndicator(me, &thumbRect);
  346.             }
  347.             if (thumbRegion) DisposeRgn(thumbRegion);
  348.             if (ctlRegion) DisposeRgn(ctlRegion);
  349.             if (oldRegion) DisposeRgn(oldRegion);
  350.             break;
  351.         default:
  352.         case inPageUp:
  353.         case inPageDown:
  354.         break;
  355.     }
  356.     if (privData)
  357.         (*privData)->oldValue = (*me)->contrlValue;
  358.     SetPenState(&oldState);
  359. }
  360. /*************** CleanOldThumb *************
  361. ***** We've gotten a message to draw the thumb, which
  362. ***** implies we have to eradicate the old thumb *******/
  363. void CleanOldThumb(ControlHandle me, Rect *thumbRect)
  364. {
  365.     PrivateHandle    privData;
  366.     short            oldValue, currValue;
  367.     short            diameter;
  368.     Rect            grayRect, ctlRect, oldThumb, whiteRect;
  369.     Boolean         upAndDown;
  370.     Pattern            grayPattern;
  371.     
  372.     privData = (PrivateHandle)(*me)->contrlData; // privData has already been tested
  373.     currValue = (*me)->contrlValue;
  374.     oldValue = (*privData)->oldValue;
  375.     
  376.     //if (currValue == oldValue) return;
  377.     
  378.     (*me)->contrlValue = oldValue;
  379.     CalcGrayRect(me, &grayRect, &whiteRect);
  380.     (*me)->contrlValue = currValue;
  381.     
  382.     CopyRect(&(*me)->contrlRect, &ctlRect);
  383.     diameter = CalcRounding(&ctlRect);
  384.     upAndDown = ((ctlRect.right - ctlRect.left) <= (ctlRect.bottom - ctlRect.top));
  385.     
  386.     CalcThumbRects(me, oldValue, &oldThumb);
  387.     GetIndPattern(grayPattern, 0, 1);// black
  388.     PenPat(&grayPattern);
  389.  
  390.     if (oldValue > currValue)
  391.     {
  392.         if (upAndDown)
  393.         {
  394.             oldThumb.bottom = thumbRect->bottom;
  395.         }
  396.         else
  397.         {
  398.             oldThumb.left = thumbRect->left;
  399.         }
  400.         FillRoundRect(&oldThumb, diameter, diameter, &grayPattern);
  401.     }
  402.     else
  403.     {
  404.         if (upAndDown)
  405.         {
  406.             oldThumb.top = thumbRect->top;
  407.         }
  408.         else
  409.         {
  410.             oldThumb.right = thumbRect->right;
  411.         }
  412.         EraseRoundRect(&oldThumb, diameter, diameter);
  413.     }
  414.     FrameRoundRect(&ctlRect, diameter, diameter);
  415. }
  416. /********** DrawMyIndicator ************
  417. ******* Draw the thumb, the thumbRect must be previously
  418. ******* calculated ******/
  419. void DrawMyIndicator(ControlHandle me, Rect *thumbRect)
  420. {
  421.     Rect        ctlRect;
  422.     Boolean     useColorQD, dimmed = FALSE;
  423.     RGBColor    newColor, oldColor;
  424.     Pattern        grayPattern;
  425.     Boolean        upAndDown;
  426.     short        diameter;
  427.     PrivateHandle    privData;
  428.     
  429.     privData = (PrivateHandle)(*me)->contrlData;
  430.     
  431.     if ((*me)->contrlMin >= (*me)->contrlMax) dimmed = TRUE;
  432.     if ((*me)->contrlHilite == 255) dimmed = TRUE;
  433.     
  434.     
  435.     if (!dimmed)
  436.     {
  437.         CopyRect(&(*me)->contrlRect, &ctlRect);
  438.         diameter = CalcRounding (&ctlRect);
  439.         
  440.     
  441.         // calculate the rectangles used in drawing
  442.         useColorQD = UseColorQD(me, thumbRect);
  443.         // start actual drawing
  444.         if(useColorQD && privData)
  445.         {
  446.             GetForeColor(&oldColor);
  447.             RGBForeColor(&(*privData)->thumbColor);    // real medium gray
  448.             GetIndPattern(grayPattern, 0, 1);// standard black for fill
  449.             FillRoundRect(thumbRect, diameter, diameter, &grayPattern);
  450.             RGBForeColor(&oldColor);
  451.         }
  452.         else
  453.         {
  454.             GetIndPattern(grayPattern, 0, 4);// standard gray for fill
  455.             FillRoundRect(thumbRect, diameter, diameter, &grayPattern);
  456.         }
  457.         FrameRoundRect(thumbRect, diameter, diameter);
  458.     }
  459. }
  460. /***************** CalcThumbRects ******
  461. **** should be CalcThumbRect, just figure what the bounding rect of
  462. *** the thumb should be given the value *******/
  463. void CalcThumbRects(ControlHandle me, short value, 
  464.         Rect *roundThumb)
  465. {
  466.     long    width, height, thumbLen;
  467.     Point    valuePoint;
  468.     Rect    ctlRect;
  469.     
  470.     CopyRect(&(*me)->contrlRect, &ctlRect);
  471.     CopyRect(&ctlRect, roundThumb);
  472.     
  473.     height = ctlRect.bottom - ctlRect.top;
  474.     width = ctlRect.right - ctlRect.left;
  475.     
  476.     MapValue2Point(me, value, &valuePoint);
  477.     thumbLen = CalcThumbLen(&ctlRect);
  478.     // calculate the rectangles used in drawing
  479.     if (height >= width)
  480.     {
  481.         roundThumb->top = valuePoint.v - thumbLen/2;
  482.         roundThumb->bottom = roundThumb->top+thumbLen;
  483.         
  484.     }
  485.     else
  486.     {
  487.         roundThumb->right = valuePoint.h + thumbLen/2;
  488.         roundThumb->left = roundThumb->right - thumbLen;
  489.     }
  490. }
  491. /********** CalcThumbLen *********
  492. **** figure how high or wide the thumb should be (given
  493. **** that some moron might have made the control too small ***/
  494. short CalcThumbLen(Rect *ctlRect)
  495. {
  496.     short    height, width;
  497.     short    result;
  498.     height = ctlRect->bottom - ctlRect->top;
  499.     width = ctlRect->right - ctlRect->left;
  500.     if (width > height)
  501.     {
  502.         result = (width > 20)?20:width;
  503.     }
  504.     else
  505.     {
  506.         result = (height > 20)?20:height;
  507.     }
  508.     return (result);
  509. }
  510. /********* DrawMyFrame **********
  511. ******* Draw the black portion of the control (pageup)
  512. ******* and frame the whole thing ********/
  513. void DrawMyFrame(ControlHandle me, Rect *grayRect)
  514. {    
  515.     Rect        ctlRect;
  516.     Boolean     useColorQD, dimmed = FALSE;
  517.     RGBColor    newColor, oldColor;
  518.     Pattern        grayPattern;
  519.     PrivateHandle    privData;
  520.     short         min, max, diameter;
  521.     privData = (PrivateHandle)(*me)->contrlData;
  522.     
  523.     CopyRect(&(*me)->contrlRect, &ctlRect);
  524.     useColorQD = UseColorQD(me, &ctlRect);
  525.     min = (*me)->contrlMin;
  526.     max = (*me)->contrlMax;
  527.     diameter = CalcRounding (&ctlRect);
  528.     if (min >= max) 
  529.     {
  530.         dimmed = TRUE;
  531.     }
  532.     if ((*me)->contrlHilite == 255) dimmed = TRUE;
  533.     
  534.     if (!dimmed)
  535.     {
  536.         GetIndPattern(grayPattern, 0, 1);// standard black for frame and top region
  537.         FillRoundRect(grayRect,diameter, diameter, &grayPattern);
  538.         PenPat(&grayPattern);
  539.     }
  540.     if(useColorQD && privData)
  541.     {
  542.         GetForeColor(&oldColor);
  543.         RGBForeColor(&(*privData)->frameColor);    
  544.         FrameRoundRect(&ctlRect, diameter, diameter);
  545.         RGBForeColor(&oldColor);
  546.     }
  547.     else
  548.         FrameRoundRect(&ctlRect, diameter, diameter);
  549. }
  550. /*********** CalcGrayRect
  551. ***** figure out the rectangle which enclose the pageup and pagedown
  552. ***** parts of the control (they meet in the middle of the thumb) ***/
  553. void    CalcGrayRect(ControlHandle me, Rect *grayRect, Rect *whiteRect)
  554. {
  555.     long    height, width, value, max, min;
  556.     Point    valuePoint;  
  557.     short    thumbLen, halfThumb;
  558.     
  559.     
  560.     value = (*me)->contrlValue;
  561.     min = (*me)->contrlMin;
  562.     max = (*me)->contrlMax;
  563.     if (value > max) // too big, who let this in?
  564.         value = max;
  565.     else if (value < min) // too small
  566.         value = min;
  567.     MapValue2Point(me,value, &valuePoint);
  568.     
  569.     CopyRect(&(*me)->contrlRect, grayRect);
  570.     CopyRect(grayRect, whiteRect);
  571.     thumbLen = CalcThumbLen(grayRect);
  572.     halfThumb = thumbLen /2;
  573.     width = grayRect->right - grayRect->left;
  574.     height = grayRect->bottom - grayRect->top;
  575.     if (width > height) // we are going side to side
  576.     {
  577.         grayRect->left = valuePoint.h - halfThumb;
  578.         whiteRect->right = valuePoint.h;
  579.     }
  580.     else
  581.     { // halfThumb is because quickdraw sort of bales out
  582.         // when round rects are small 
  583.         grayRect->bottom = valuePoint.v + halfThumb;
  584.         whiteRect->top = valuePoint.v;
  585.     }
  586. }
  587. /******* CalcRounding *******
  588. ****** are we big enough to use round rectangles 
  589. if so use 16 diameter rounding, if not use square corners ****/
  590. short CalcRounding(Rect *ctlRect)
  591. {
  592.     short    width, height;
  593.     width = ctlRect->right - ctlRect->left;
  594.     height = ctlRect->bottom - ctlRect->top;
  595.     if (width > height)
  596.     {
  597.         if (width > 64)
  598.             return (16);
  599.     }
  600.     else
  601.     {
  602.         if (height > 64)
  603.             return (16);
  604.     }
  605.     return (0);
  606. }
  607.  
  608. /******** InitMe ********
  609. ****** allocate my global memory, test for color and load color table
  610. ****** information ****/
  611. void InitMe(ControlHandle me)
  612. {
  613.     PrivateHandle    privDataH;
  614.     AuxCtlHandle        acHndl;
  615.     CCTabHandle        tableH;
  616.     short            tabLen;
  617.     RGBColor        *tempColor;
  618.     privDataH = (PrivateHandle)NewHandleClear(sizeof(Private));
  619.     if (privDataH)
  620.     {
  621.         if ((*privDataH)->useColorQD = TestForColor())
  622.         {// we are using color, find the highlight color
  623.             tempColor = &(*privDataH)->frameColor;
  624.             tempColor->red = tempColor->blue = tempColor->green = 0; // black
  625.             tempColor = &(*privDataH)->thumbColor; 
  626.             tempColor->blue = tempColor->green = tempColor->red = 30583; // gray
  627.             GetAuxCtl(me, &acHndl);
  628.             if (acHndl)
  629.             {
  630.                 tableH = (*acHndl)->acCTable;
  631.                 tabLen = (*tableH)->ctSize;
  632.                 while(tabLen >= 0)
  633.                 {
  634.                     if ((*tableH)->ctTable[tabLen].value == cFrameColor)
  635.                     {
  636.                         BlockMove(&(*tableH)->ctTable[tabLen].rgb, 
  637.                             &(*privDataH)->frameColor, sizeof(RGBColor));
  638.                     }
  639.                     /* else if ((*tableH)->ctTable[tabLen].value == cThumbColor)
  640.                     {
  641.                         BlockMove(&(*tableH)->ctTable[tabLen].rgb, 
  642.                             &(*privDataH)->thumbColor, sizeof(RGBColor));
  643.                     } */
  644.                     tabLen--;
  645.                 }
  646.             }
  647.         }
  648.         // we need to know if we can call GetDeviceList to tell whether 
  649.         // or not our control is on a deep color screen
  650.         (*privDataH)->devicesAvailable = TrapAvailable(0xAA29);
  651.         
  652.         (*privDataH)->oldValue = (*me)->contrlValue;
  653.     }
  654.     (*me)->contrlData = (Handle)privDataH;
  655. }
  656.  
  657.  
  658.